<%@page import="org.apache.shiro.SecurityUtils"%>
<%@page import="org.apache.shiro.subject.Subject"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@ include file="/WEB-INF/pages/common/taglib.jsp"%>
<%
    Subject subject = SecurityUtils.getSubject();
    boolean hasLogined=false;
    if(subject!=null && subject.isAuthenticated()){
    	hasLogined=true;
    }
%>
<html>
<head>
<title>易联工单管理系统</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@ include file="/WEB-INF/pages/common/includeCoreCssJs.jsp"%>
<link rel="stylesheet" href="${root}/res/webpage/css/main.css">
<style>
</style>
</head>
<body>

<div class="main">
	<div class="top">
    	<div class="top_left"><a href="#"><img width="350" src="${root}/res/webpage/images/logo.jpg" /></a></div>
    	<div class="top_right">
        	<p class="top_right_a1 login"><a href="javascript:void(0)" id="loginDialogBt">请点击登录</a></p>
        	<p class="top_right_a1 logout" style="display: none;">欢迎您，<a href="#" id="userName"></a>，<a href="javascript:void(0)" id="logoutBt">退出</a></p>
            <p class="top_right_a2"><span class="logout"  style="display: none;">您的工作组为：<span class="red currentGroups">未选择工作组</span>，您的状态为：<span class="red onlineStateStr">离线</span></span></p>
        </div>
    </div>
</div>
<div class="clear"></div>
    
<div class="nav_box">
    <ul id="nav"> 
        <li><a href="#" _fcksavedurl="#">DNA平台</a></li> 
        <li><a href="#" _fcksavedurl="#">插件平台</a></li> 
        <li><a href="#" _fcksavedurl="#">代收付平台</a> 
            <ul> 
                <li><a href="#" _fcksavedurl="#">代付查询</a></li> 
                <li><a href="#" _fcksavedurl="#">收款查询</a></li>
            </ul> 
        </li>
    </ul> 
</div>

<div class="main">
	<div class="box1_left">
		<ul>
			<iframe src="${root}/sipml5/call87.htm?phone=99300&&password=a12345&&address=10.123.65.69" width="100%" height="100px" scroll="no" scrolling="no" frameborder="no"> </iframe>
		</ul>
    	<ul>
        	<li class="box1_left_b1"><a href="#">话务处理</a></li>
        	<li class="box1_left_b2"><a href="${ctx}/workOrderAct/workOrderIndex.do">工单处理</a></li>
        	<li class="box1_left_b3"><a href="javascript:void(0)" data-onlinestate="1" id="toggleOnline">状态：<span class="onlineStateStr">离线</span></a></li>
        </ul>
    	<ul>
        	<li class="box1_left_b4"><a href="#">知识库</a></li>
        	<li class="box1_left_b5"><a href="#">线路状态</a></li>
        	<li class="box1_left_b6"><a href="#">统计</a></li>
        	<li class="box1_left_b7"><a href="#">帮助</a></li>
        </ul>
    	<ul>
        	<li class="box1_left_b8"><a href="${ctx}/woIndexAct/toSysMain.do" target="_blank">设置</a></li>
        	<li class="box1_left_b9"><a href="javascript:void(0)" class="myWorkGroupBtn">我的工作组</a></li>
        	<li class="box1_left_b10"><a href="#">预留位置</a></li>
        </ul>
    </div>
	<div class="box1_right">
		<span>公告栏</span>
		<button type="button" id="winOpen" style="display:none;"></button>
		<input id="winOpenVal" type="input" style="display:none;">
    	<ul id="noticeBox">
        	
        </ul>
    </div>
</div>
<div class="clear" style="height:80px;"></div>

<div class="copyright">
	<div class="main">易联支付有限公司(C)版权所有   |    ICP证： 粤B2-20120038   |    B2-20110256   |    短消息号:[2012]00200-A011</div>
</div>
<div class="bottom">
	<div class="main">
    	<div class="bottom_left"><a href="#"><img src="${root}/res/webpage/images/b_logo.jpg" /></a></div>
    	<div class="bottom_right">中国人民银行支付业务许可证号：Z2006444000010</div>
    </div>
</div>
<%@ include file="/WEB-INF/pages/common/includeUiScript.jsp"%>
<script type="text/javascript">

window.onbeforeunload=function(){
	changeOnlineState(1);
}


$(function(){
	var currentUser;
	var hasLogin='<%=hasLogined%>'
	$("#loginDialogBt").click(function(){
		var r=webUtils.dialog({
			title:"用户登录",
			url:root+"/Login.jsp"
		});
	});
	
	$("#logoutBt").click(function(){
		changeOnlineState(1);
		window.location.href=ctx+"/logout.do"
	});
	
	if(hasLogin && hasLogin=='true'){
		$(".login").hide();
		$(".logout").show();
		
		currentUser=webUtils.getCurrentUser();
		if(currentUser){
			$("#userName").html(currentUser.userName);
		}
		
		changeOnlineState(2);
		updateGroupStr();
	}
	
	/*	读取通知公告	*/
	var titlesize=12;
	var noticeBox=$("#noticeBox");
	$.getJSON(ctx+"/oaNoticeAct/loadTop.do",{pageSize:12},function(ds){
		$.each(ds.rows,function(i,n){
			var title=n.TITLE;
			title=title.length>titlesize?title.subStr(0,titlesize)+"..":title;
			var link=n.CONTENTTYPE==2?n.LINK:ctx+"/oaNoticeAct/view.do?id="+n.ID;
			var tpl='<li><a href="'+link+'" target="_blank">'+title+'</a><span>'+webUtils.parseTimestamp(n.CREATETIME,"yyyy.MM.dd")+'</span></li>';
			noticeBox.append(tpl);
		});
	});
	
	/*	我的工作组	*/
	$(".myWorkGroupBtn").click(function(){
		webUtils.on("userGroup.save.success",function(){
			updateGroupStr();
			r.close();
		},true);
		var r=webUtils.dialog({
			title:"我的工作组",
			width:550,
			url:ctx+"/userGroupAct/mySettingView.do"
		});
	});
	
	/*	切换在线离线状态	*/
	$("#toggleOnline").click(function(){
		var $this=$(this);
		if($this.data("onlinestate")==2){
			changeOnlineState(1);
		}else{
			changeOnlineState(2);
		}
	});
	
});

function changeOnlineState(state){
	var $this=$("#toggleOnline");
	var changeState=state;
	var changeStateStr=changeState==1?"离线":"在线";
	$.post(ctx+"/userAction/updateOnlineState.do",{state:changeState},function(d){
		if(d.success){
			$this.data("onlinestate",changeState)
			$(".onlineStateStr").html(changeStateStr);
		}else{
			webUtils.error(d.msg);
		}
	},"json");
}

function updateGroupStr(){
	$.getJSON(ctx+"/userGroupAct/loadUserGroups.do",function(gs){
		var strs=[];
		$.each(gs,function(gi,gn){
			strs.push(gn.title);
		});
		if(strs.length>0){
			$(".currentGroups").html(strs.join(","));
		}
	});
}

//客服登陆后到后台添加客服信息到redis
function updateSipStatus(){
	$.post(ctx+"/loginStatusAct/loginSIP.do",{abilityId:"123",userIds:"456"},function(d){
	},"json");
}

//客服生命线方法
function lifeline_redis(){
	$.post(ctx+"/loginStatusAct/lifeLineSIP.do",{},function(d){
	},"json");
}

//客服登出方法
function loginoutSIP(){
	$.post(ctx+"/loginStatusAct/loginout.do",{},function(d){
	},"json");
}

//客服状态转状态方法
function changeSipStatus(){
	$.post(ctx+"/loginStatusAct/changeStatus.do",{},function(d){
	},"json");
}

//接听电话后跳转到工单页面
function href_to_nagiv(e){
	//alert(e);
	//window.open("${ctx}/workOrderAct/workOrderIndex.do?phone="+e);
	$("#winOpenVal").val(e);
}
function href_to_open(){
	$("#winOpen").click();
}
$("#winOpen").click(function(){ 
	window.open("${ctx}/workOrderAct/workOrderIndex.do?phone="+$("#winOpenVal").val());
});
</script>
</body>
</html>

